// pages/interests/interests.js

import mode from '../../utils/mode'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        catScore:'',    //还差多少分到下一等级
        rules:[],    //积分等级规则
        blackWidth:'',
        score: 0,
        score_info: {
            gradeName: "银钻等级",
        },
        scoreLevel:1,   //会员等级
        interests: [{
            url: '../../image/icon/Group7802.png',
            title: [
                '参与积分及银钻积分兑换礼遇',
                '4000积分，直通金钻等级'
            ]
        },
        {
            url: '../../image/icon/e15ec7901669f71f6060dcfb4bdd38e.png',
            title: [
                '各类优惠活动和礼券',
                '详情以品牌活动的规则为准'
            ]
        }
        ],
        interests1: [{
            url: '../../image/icon/Group7802.png',
            title: [
                '晋级金钻，立刻获赠产品礼',
                '金钻等级后再累积4500分',
                ' 再获赠黑钻在望礼'
            ]
        },
        {
            url: '../../image/icon/envelopes@2x.png',
            title: [
                '生日红包',
                '周年复审日积分满500，',
                '可获赠生日礼券'
            ]
        },
        {
            url: '../../image/icon/f6e44fc327de794a4f21cb0bebbc800.png',
            title: [
                'VIP折扣',
                '官方小程序渠道购买即可享受'
            ]
        },
        {
            url: '../../image/icon/600d53ae09ea047a8df9773d86020ea.png',
            title: [
                '各类商品兑换及优惠活动',
                '享受金钻好礼兑换礼遇'
            ]
        }
        ],
        interests2: [{
            url: '../../image/icon/Group7802.png',
            title: ['晋级黑钻，立刻获赠产品礼']
        },
        {
            url: '../../image/icon/nursing@2x.png',
            title: [
                '每月获赠美容护理券',
                '现金抵扣月月享'
            ]
        },
        {
            url: '../../image/icon/envelopes@2x.png',
            title: ['生日红包', ' 周年复审日积分满500，','可获赠生日礼券']
        },
        {
            url: '../../image/icon/anniversary@2x.png',
            title: ['周年庆礼',
                '周年复审日时，年消费积分累积满9000，可获赠周年庆商品礼']
        },
        {
            url: '../../image/icon/f6e44fc327de794a4f21cb0bebbc800.png',
            title: [
                'VIP折扣',
                '官方小程序渠道购买即可享受'
            ]
        },
        {
            url: '../../image/icon/600d53ae09ea047a8df9773d86020ea.png',
            title: [
                '各类商品兑换及优惠活动',
                '独享黑钻兑换礼遇'
            ]
        }
        ],
        IntegralRule: [{
            url: '../../image/icon/tubiao.png',
            title: ''
        },
        {
            url: '../../image/icon/Group7769@2x.png',
            title: '生日红包 周年复审日积分满500， 可获赠生日礼券'
        },
        ],
        show: false,
        goos_set: '',
        service_set: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.getScoreSet()
        

    },
    handleOpen () {
        this.popupShowToggle()
    },
    onClose () {
        this.popupShowToggle()
    },
    popupShowToggle () {
        const {
            show
        } = this.data
        this.setData({
            show: !show
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var uinfo = wx.getStorageSync('uinfo')
        let levelName = ''
        if(uinfo.user.grade==1){
            levelName='银钻等级'
        }else if(uinfo.user.grade==2){
            levelName='金钻等级'
        }else if(uinfo.user.grade==3){
            levelName='黑钻等级'
        }
        this.setData({
            userMessage: uinfo.user,
            score: uinfo.user.score,
            scoreLevel:uinfo.user.grade,
            'score_info.gradeName':levelName
        })
        this.getRule()
    },
    toMyScore () {
        if(this.data.score>0||this.data.score_info.point>0){
            wx.navigateTo({
                url: '/pages/record/record',
            })
        }
    },
    getRule(){    //获取等级规则
        var that = this
        wx.$api.getUserLevel().then(res=>{
                if(res.code==1){
                    that.setData({
                        rules:res.data
                    })
                    let catScore = ''
                    let blackWidth = ''
                    let score = that.data.userMessage.score
                    if(that.data.scoreLevel==1){
                        blackWidth = (score/that.data.rules[1].integral*100)
                        catScore = that.data.rules[1].integral - score
                    }else if(that.data.scoreLevel==2){
                        blackWidth = (score/that.data.rules[2].integral*100)
                        catScore = that.data.rules[2].integral - score
                    }
                    blackWidth = blackWidth>100?100:blackWidth
                    let width = blackWidth +'%'
                    that.setData({ 
                        blackWidth:width,
                        catScore:catScore
                    })
                }
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    getScoreSet () {
        var that = this
        wx.$api.getScoreSet().then(res=>{
                that.setData({
                    goos_set: res.data.consumption,
                    service_set: res.data.service
                })
        })
    },
    toTiaoKuan () {
        wx.navigateTo({
            url: '../police/police',
        })
    },
})